package org.jeecg.modules.demo.ch.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.demo.ch.entity.ChCurrentEquipmentManagement;
import org.jeecg.modules.demo.ch.service.IChCurrentEquipmentManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.Date;

/**
 * @Description: 现行设备管理
 * @Author: jeecg-boot
 * @Date:   2022-12-16
 * @Version: V1.0
 */
@Api(tags="现行设备管理")
@RestController
@RequestMapping("/ch/chCurrentEquipmentManagement")
@Slf4j
public class ChCurrentEquipmentManagementController extends JeecgController<ChCurrentEquipmentManagement, IChCurrentEquipmentManagementService> {
	@Autowired
	private IChCurrentEquipmentManagementService chCurrentEquipmentManagementService;

	/**
	 * 分页列表查询
	 *
	 * @param chCurrentEquipmentManagement
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "现行设备管理-分页列表查询")
	@ApiOperation(value="现行设备管理-分页列表查询", notes="现行设备管理-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<ChCurrentEquipmentManagement>> queryPageList(ChCurrentEquipmentManagement chCurrentEquipmentManagement,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   String equipmentPurchaseDate_begin,
								   String equipmentPurchaseDate_end,
								   String entryDate_begin,
								   String entryDate_end,
								   HttpServletRequest req) {
		log.info("传过来的参数chCurrentEquipmentManagement:{},equipmentPurchaseDate_begin:{},equipmentPurchaseDate_end:{},entryDate_begin:{},entryDate_end:{}",chCurrentEquipmentManagement,equipmentPurchaseDate_begin,equipmentPurchaseDate_end,entryDate_begin,entryDate_end);
//		QueryWrapper<ChCurrentEquipmentManagement> queryWrapper = QueryGenerator.initQueryWrapper(chCurrentEquipmentManagement, req.getParameterMap());
		String name = chCurrentEquipmentManagement.getName();//名称
		String type = chCurrentEquipmentManagement.getType();//类型
		String status = chCurrentEquipmentManagement.getStatus();//状态
		String equipmentManager = chCurrentEquipmentManagement.getEquipmentManager();//设备管理人
		String equipmentFixedAssetNo = chCurrentEquipmentManagement.getEquipmentFixedAssetNo();//设备固定资产编号
		String itAssetNumber = chCurrentEquipmentManagement.getItAssetNumber();//IT资产编号
		String remark = chCurrentEquipmentManagement.getRemark();//备注
		String enteredBy = chCurrentEquipmentManagement.getEnteredBy();//录入人

		LambdaQueryWrapper<ChCurrentEquipmentManagement> chCurrentEquipmentManagementLambdaQueryWrapper = new QueryWrapper<ChCurrentEquipmentManagement>().lambda()
				.like(StringUtils.hasLength(name), ChCurrentEquipmentManagement::getName, name)
				.like(StringUtils.hasLength(type), ChCurrentEquipmentManagement::getType, type)
				.like(StringUtils.hasLength(status), ChCurrentEquipmentManagement::getStatus, status)
				.like(StringUtils.hasLength(equipmentManager), ChCurrentEquipmentManagement::getEquipmentManager, equipmentManager)
				.like(StringUtils.hasLength(equipmentFixedAssetNo), ChCurrentEquipmentManagement::getEquipmentFixedAssetNo, equipmentFixedAssetNo)
				.like(StringUtils.hasLength(itAssetNumber), ChCurrentEquipmentManagement::getItAssetNumber, itAssetNumber)
				.like(StringUtils.hasLength(remark), ChCurrentEquipmentManagement::getRemark, remark)
				.like(StringUtils.hasLength(enteredBy), ChCurrentEquipmentManagement::getEnteredBy, enteredBy)
				.ge(StringUtils.hasLength(equipmentPurchaseDate_begin), ChCurrentEquipmentManagement::getEquipmentPurchaseDate, equipmentPurchaseDate_begin)
				.le(StringUtils.hasLength(equipmentPurchaseDate_end), ChCurrentEquipmentManagement::getEquipmentPurchaseDate, equipmentPurchaseDate_end)
				.ge(StringUtils.hasLength(entryDate_begin), ChCurrentEquipmentManagement::getEntryDate, entryDate_begin)
				.le(StringUtils.hasLength(entryDate_end), ChCurrentEquipmentManagement::getEntryDate, entryDate_end);
		Page<ChCurrentEquipmentManagement> page = new Page<ChCurrentEquipmentManagement>(pageNo, pageSize);
		IPage<ChCurrentEquipmentManagement> pageList = chCurrentEquipmentManagementService.page(page, chCurrentEquipmentManagementLambdaQueryWrapper);
		return Result.OK(pageList);
	}

	/**
	 *   添加
	 *
	 * @param chCurrentEquipmentManagement
	 * @return
	 */
	@AutoLog(value = "现行设备管理-添加")
	@ApiOperation(value="现行设备管理-添加", notes="现行设备管理-添加")
	//@RequiresPermissions("org.jeecg.modules.demo:ch_current_equipment_management:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody ChCurrentEquipmentManagement chCurrentEquipmentManagement) {
		//设置录入时间
		chCurrentEquipmentManagement.setEntryDate(new Date());
		chCurrentEquipmentManagementService.save(chCurrentEquipmentManagement);
		return Result.OK("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param chCurrentEquipmentManagement
	 * @return
	 */
	@AutoLog(value = "现行设备管理-编辑")
	@ApiOperation(value="现行设备管理-编辑", notes="现行设备管理-编辑")
	//@RequiresPermissions("org.jeecg.modules.demo:ch_current_equipment_management:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody ChCurrentEquipmentManagement chCurrentEquipmentManagement) {
		chCurrentEquipmentManagementService.updateById(chCurrentEquipmentManagement);
		return Result.OK("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "现行设备管理-通过id删除")
	@ApiOperation(value="现行设备管理-通过id删除", notes="现行设备管理-通过id删除")
	//@RequiresPermissions("org.jeecg.modules.demo:ch_current_equipment_management:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		chCurrentEquipmentManagementService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "现行设备管理-批量删除")
	@ApiOperation(value="现行设备管理-批量删除", notes="现行设备管理-批量删除")
	//@RequiresPermissions("org.jeecg.modules.demo:ch_current_equipment_management:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.chCurrentEquipmentManagementService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "现行设备管理-通过id查询")
	@ApiOperation(value="现行设备管理-通过id查询", notes="现行设备管理-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<ChCurrentEquipmentManagement> queryById(@RequestParam(name="id",required=true) String id) {
		ChCurrentEquipmentManagement chCurrentEquipmentManagement = chCurrentEquipmentManagementService.getById(id);
		if(chCurrentEquipmentManagement==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(chCurrentEquipmentManagement);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param chCurrentEquipmentManagement
    */
    //@RequiresPermissions("org.jeecg.modules.demo:ch_current_equipment_management:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ChCurrentEquipmentManagement chCurrentEquipmentManagement) {
        return super.exportXls(request, chCurrentEquipmentManagement, ChCurrentEquipmentManagement.class, "现行设备管理");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    //@RequiresPermissions("ch_current_equipment_management:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ChCurrentEquipmentManagement.class);
    }

}
